package net.zjict.lib.structural.proxy.computer;

import java.lang.reflect.Proxy;

/**
 * 动态客户端
 */
public class DynamicClient {
    public static void main(String[] args) {
        //创建加法真实主题
        AddSubject realAddSubject=new RealAddSubject();
        //创建动态代理
        DynamicCalculation<AddSubject> mDynamicCalculation=new DynamicCalculation<AddSubject>(realAddSubject);
        //创建加法真实主题的ClassLoader
        ClassLoader addClassLoader=realAddSubject.getClass().getClassLoader();
        //动态创建加法代理类
        AddSubject addSubject= (AddSubject) Proxy.newProxyInstance(addClassLoader,realAddSubject.getClass().getInterfaces(),mDynamicCalculation);
        addSubject.computer(5,6);

        //创建除法真实主题
        DiverSubject diverSubject=new RealDiverSubject();
        //创建动态代理
        DynamicCalculation<DiverSubject> DynamicCalculation=new DynamicCalculation<>(diverSubject);
        //创建除法真实主题的ClassLoader
        ClassLoader diverClassLoader=diverSubject.getClass().getClassLoader();
        //动态创建除法代理类

    }
}
